package com.fbee.smartcommunities.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fbee.smartcommunities.entity.Complains;
import com.fbee.smartcommunities.entity.Visitor;
import com.fbee.smartcommunities.service.ComplainsService;
import com.fbee.smartcommunities.vo.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-22
 */
@RestController
@RequestMapping("/complains")
public class ComplainsController {

    @Resource
    private ComplainsService complainsService;

    // 分页后内容
    @GetMapping("/list")
    public ResultVO<IPage<Complains>> getPage(Integer pageNo, Integer pageSize, String target,Boolean state) {
        return ResultVO.success(complainsService.getPage(pageNo,pageSize,target,state));
    }

    @PostMapping("/changeState")
    public ResultVO<Boolean> changeState(Long id,Boolean state,String key){
        return ResultVO.success(complainsService.changeState(id,state,key),"修改成功");
    }

    @PostMapping("/add")
    public ResultVO<Boolean> addComplain(String target,String content){
        return ResultVO.success(complainsService.save(new Complains(target,content,0)),"提交成功");
    }

}
